package springboot.service.impl;

import org.springframework.stereotype.Service;
import springboot.Tools.Date.Day;
import springboot.Tools.Date.StartAndEndTime;
import springboot.dao.WxGroupChatAdminDao;
import springboot.doMain.WxGroupChatAdmin;
import springboot.service.WXGroupChatAdminService;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * wxWork
 * springboot.service.impl
 * Created by Blue on 2021/11/2.
 */
@Service
public class WXGroupChatAdminServiceImpl implements WXGroupChatAdminService {
	
	final
	WxGroupChatAdminDao wxGroupChatAdminDao;
	
	public WXGroupChatAdminServiceImpl(WxGroupChatAdminDao wxGroupChatAdminDao) {
		this.wxGroupChatAdminDao = wxGroupChatAdminDao;
	}
	
	@Override
	public int deleteByPrimaryKey(Long groupChatSellerId) {
		return 0;
	}
	
	@Override
	public int insert(WxGroupChatAdmin record) {
		System.out.println("record = " + record);
		return wxGroupChatAdminDao.insert(record);
	}
	
	@Override
	public List<Map<String, Object>> selPeriodSellerData(Day day) {
		if (day == null) {
			return null;
		}
		long start = day.getDayStartTime().getTime() / 1000;
		long end = day.getDayEndTime().getTime() / 1000;
		return wxGroupChatAdminDao.selPeriodSellerData(start, end);
	}
	
	@Override
	public List<Map<String, String>> selPeriodSellerDataByAnother(long date) {
		
		return wxGroupChatAdminDao.selPeriodSellerDataByAnother(date);
	}
	
	public List<Map<String, String>> selPeriodSellerDataByAnother(int diff) {
		Day day = StartAndEndTime.getDay(diff - 1);
		Date dayStartTime = day.getDayStartTime();
		return selPeriodSellerDataByAnother(dayStartTime.getTime() / 1000);
	}
	
	
	@Override
	public int insertSelective(WxGroupChatAdmin record) {
		return wxGroupChatAdminDao.insertSelective(record);
	}
	
	@Override
	public WxGroupChatAdmin selectByPrimaryKey(Long groupChatSellerId) {
		return null;
	}
	
	@Override
	public int updateByPrimaryKeySelective(WxGroupChatAdmin record) {
		return 0;
	}
	
	@Override
	public int updateByPrimaryKey(WxGroupChatAdmin record) {
		return 0;
	}
	
	@Override
	public int insertDayGroupChat(List<WxGroupChatAdmin> wxGroupChatAdmins) {
		if (wxGroupChatAdmins == null) {
			return 0;
		}
		WxGroupChatAdmin wxGroupChatAdmin = wxGroupChatAdmins.get(0);
		int i;
		if (wxGroupChatAdmin == null) {
			return 0;
		}
		i = wxGroupChatAdminDao.selIsExistByDate(wxGroupChatAdmin.getTimeStamp());
		if (i < 1) {
			try {
				wxGroupChatAdmins.forEach(wxGroupChatAdmin1 -> {
					int insert = this.insert(wxGroupChatAdmin1);
					System.out.println("insert = " + insert);
				});
			} catch (Exception e) {
				e.printStackTrace();
				return -1;
			}
		} else {
			try {
				wxGroupChatAdmins.forEach(wxGroupChatAdminDao::updateByDateAndUserId);
			} catch (Exception e) {
				e.printStackTrace();
				return -2;
			}
			return 2;
		}
		return 0;
	}
	
	@Override
	public List<Map<String, Object>> selSellerData(int diff) {
		return wxGroupChatAdminDao.selSellerData(diff);
	}
}
